package cz.vutbr.fit.xzemko01.tfmcbs.diagram.part;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.gef.Tool;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeConnectionTool;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeCreationTool;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;

import cz.vutbr.fit.xzemko01.tfmcbs.diagram.providers.ComponentBasedSystemElementTypes;

/**
 * @generated
 */
public class ComponentBasedSystemPaletteFactory {

	/**
	 * @generated
	 */
	public void fillPalette(PaletteRoot paletteRoot) {
		paletteRoot.add(createTfmcbs1Group());
	}

	/**
	 * Creates "tfmcbs" palette tool group
	 * @generated
	 */
	private PaletteContainer createTfmcbs1Group() {
		PaletteGroup paletteContainer = new PaletteGroup(
				Messages.Tfmcbs1Group_title);
		paletteContainer.setId("createTfmcbs1Group"); //$NON-NLS-1$
		paletteContainer.add(createSimpleComponent1CreationTool());
		paletteContainer.add(createCompositeComponent2CreationTool());
		paletteContainer.add(createInterface3CreationTool());
		paletteContainer.add(createProvidingPort4CreationTool());
		paletteContainer.add(createRequiringPort5CreationTool());
		paletteContainer.add(createRealization6CreationTool());
		paletteContainer.add(createUsage7CreationTool());
		paletteContainer.add(createManifestation8CreationTool());
		paletteContainer.add(createDependency9CreationTool());
		paletteContainer.add(createArtifact10CreationTool());
		paletteContainer.add(createGeneralization11CreationTool());
		paletteContainer.add(createDelegate12CreationTool());
		return paletteContainer;
	}

	/**
	 * @generated
	 */
	private ToolEntry createSimpleComponent1CreationTool() {
		ArrayList<IElementType> types = new ArrayList<IElementType>(2);
		types.add(ComponentBasedSystemElementTypes.SimpleComponent_2001);
		types.add(ComponentBasedSystemElementTypes.SimpleComponent_3001);
		NodeToolEntry entry = new NodeToolEntry(
				Messages.SimpleComponent1CreationTool_title,
				Messages.SimpleComponent1CreationTool_desc, types);
		entry.setId("createSimpleComponent1CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/SimpleComponentSmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/SimpleComponentLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createCompositeComponent2CreationTool() {
		ArrayList<IElementType> types = new ArrayList<IElementType>(2);
		types.add(ComponentBasedSystemElementTypes.CompositeComponent_2002);
		types.add(ComponentBasedSystemElementTypes.CompositeComponent_3002);
		NodeToolEntry entry = new NodeToolEntry(
				Messages.CompositeComponent2CreationTool_title,
				Messages.CompositeComponent2CreationTool_desc, types);
		entry.setId("createCompositeComponent2CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/CompositeComponentSmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/CompositeComponentLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createInterface3CreationTool() {
		ArrayList<IElementType> types = new ArrayList<IElementType>(2);
		types.add(ComponentBasedSystemElementTypes.Interface_3003);
		types.add(ComponentBasedSystemElementTypes.Interface_2004);
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Interface3CreationTool_title,
				Messages.Interface3CreationTool_desc, types);
		entry.setId("createInterface3CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/InterfaceSmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/InterfaceLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createProvidingPort4CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.ProvidingPort4CreationTool_title,
				Messages.ProvidingPort4CreationTool_desc,
				Collections
						.singletonList(ComponentBasedSystemElementTypes.ProvidingPort_3004));
		entry.setId("createProvidingPort4CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/ProvidingPortSmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/ProvidingPortLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createRequiringPort5CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.RequiringPort5CreationTool_title,
				Messages.RequiringPort5CreationTool_desc,
				Collections
						.singletonList(ComponentBasedSystemElementTypes.RequiringPort_3005));
		entry.setId("createRequiringPort5CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/RequiringPortSmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/RequiringPortLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createRealization6CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Realization6CreationTool_title,
				Messages.Realization6CreationTool_desc,
				Collections
						.singletonList(ComponentBasedSystemElementTypes.Realization_4003));
		entry.setId("createRealization6CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/RealizationSmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/RealizationLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createUsage7CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Usage7CreationTool_title,
				Messages.Usage7CreationTool_desc,
				Collections
						.singletonList(ComponentBasedSystemElementTypes.Usage_4004));
		entry.setId("createUsage7CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/UsageSmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/UsageLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createManifestation8CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Manifestation8CreationTool_title,
				Messages.Manifestation8CreationTool_desc,
				Collections
						.singletonList(ComponentBasedSystemElementTypes.Manifestation_4002));
		entry.setId("createManifestation8CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/ManifestationSmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/ManifestationLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createDependency9CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Dependency9CreationTool_title,
				Messages.Dependency9CreationTool_desc,
				Collections
						.singletonList(ComponentBasedSystemElementTypes.Dependency_4001));
		entry.setId("createDependency9CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/DependencySmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/DependencyLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createArtifact10CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Artifact10CreationTool_title,
				Messages.Artifact10CreationTool_desc,
				Collections
						.singletonList(ComponentBasedSystemElementTypes.Artifact_2003));
		entry.setId("createArtifact10CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/ArtifactSmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/ArtifactLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createGeneralization11CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Generalization11CreationTool_title,
				Messages.Generalization11CreationTool_desc,
				Collections
						.singletonList(ComponentBasedSystemElementTypes.Generalization_4005));
		entry.setId("createGeneralization11CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/GeneralizationSmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/GeneralizationLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createDelegate12CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Delegate12CreationTool_title,
				Messages.Delegate12CreationTool_desc,
				Collections
						.singletonList(ComponentBasedSystemElementTypes.Delegate_4006));
		entry.setId("createDelegate12CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/DelegateSmall.gif")); //$NON-NLS-1$
		entry.setLargeIcon(ComponentBasedSystemDiagramEditorPlugin
				.findImageDescriptor("icons/DelegateLarge.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private static class NodeToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> elementTypes;

		/**
		 * @generated
		 */
		private NodeToolEntry(String title, String description,
				List<IElementType> elementTypes) {
			super(title, description, null, null);
			this.elementTypes = elementTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeCreationTool(elementTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}

	/**
	 * @generated
	 */
	private static class LinkToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> relationshipTypes;

		/**
		 * @generated
		 */
		private LinkToolEntry(String title, String description,
				List<IElementType> relationshipTypes) {
			super(title, description, null, null);
			this.relationshipTypes = relationshipTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeConnectionTool(relationshipTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}
}
